{extend name="base"/}
{block name="resources"}
<style>
    input[type="checkbox"] + label::before {
        content: "\a0";  /*不换行空格*/
        display: inline-block;
        vertical-align: .2em;
        height: 18px;
        width: 18px;
        font-size: 22px;
        margin-right: .2em;
        border-radius: .2em;
        background-color: white;
        border: 1px solid #93a1a1;
        text-indent: .15em;
        line-height: .65;  /*行高不加单位，子元素将继承数字乘以自身字体尺寸而非父元素行高*/
    }
    input[type="checkbox"]:checked + label::before {
        content: "\2714";
        background-color:#00a0e9;
        color: white;
        height: 18px;
        width: 18px;
        font-size: 22px;
    }
    input[type="checkbox"] {
        position: absolute;
        clip: rect(0, 0, 0, 0);
        cursor:pointer;
    }
</style>
<link rel="stylesheet" type="text/css"  href="/public/static/umedito/themes/default/_css/umeditor.css">
<link rel="stylesheet" type="text/css" href="/public/css/defau.css">
<script type="text/javascript" src="/public/static/umedito/third-party/jquery.min.js"></script>
<script type="text/javascript" src="/public/static/umedito/third-party/template.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/public/static/umedito/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/public/static/umedito/_examples/editor_api.js"></script>
<script type="text/javascript" src="/public/static/umedito/lang/zh-cn/zh-cn.js"></script>
{/block}
{block name="main"}
<article class="cl pd-20">
    <div id="tab_demo" class="HuiTab" style="margin-bottom: 15px; position:relative;">
        <div class="tabBar clearfix">
            <span onclick="window.location.href='__CONF_SITE__admin/article/article_list'">文章列表</span>
            <span class="current">编辑文章</span>
        </div>
    </div>
    <form action="" method="post" class="form form-horizontal" id="">
        <input type="hidden" value="{$info['article_id']}" id="article_id">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>文章标题：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" autocomplete="off" value="{$info['title']}" placeholder="文章标题" class="input-text"
                       id="title">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>短标题：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" autocomplete="off" value="{$info['short_title']}" placeholder="短标题"
                       class="input-text" id="short_title">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>文章分类：</label>
            <div class="formControls col-xs-8 col-sm-2">
                <span class="select-box">
					<select class="select" id="class_id">
						<option value="-1">请选择</option>
                        {volist name="class" id="c"}
                        <option value="{$c['class_id']}" {if condition="$c.class_id==$info.class_id" } selected {/if}>{$c['name']}</option>
                        {/volist}
					</select>
				</span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>作者：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" autocomplete="off" value="{$info['author']}" class="input-text" placeholder="作者"
                       id="author">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">阅读量：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" autocomplete="off" value="{$info['click']|default=0}" class="input-text" placeholder="阅读量"
                       id="click">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">文章关键字：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" autocomplete="off" value="{$info['keyword']}" class="input-text" placeholder="文章关键字"
                       id="keyword">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">直接链接：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <input type="text" autocomplete="off" value="{$info['link']}" class="input-text" placeholder="直接链接" id="link">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">是否推荐：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="formControls col-xs-8 col-sm-3 skin-minimal">
                    <input type="checkbox" {if condition="$info.is_recommend==1" } checked {/if} id="is_recommend">
                    <label for="is_recommend">&nbsp;</label>
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>文章封面图片：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <p style="height: 165px;width:165px;border: dashed 1px #e5e5e5">
                    <img src="{$info['image']}" alt="" id="imgarticle_pic" class="thumbnail">
                </p>
                <div class="upload-btn">
				<span>
					<input type="hidden" value="{$info['image']}" id="article_pic"/>
				</span>
                    <input onclick="select_img('1','zhu');" class="btn btn-default" type="button" value="选择图片">
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>内容：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <script id="editor" type="text/plain" style="width: 100%; height: 500px;">
                    {$info['content']}
                </script></div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" onclick="addSuppAjax()" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>
{/block}
{block name="script"}
<script type="text/javascript" src="/public/static/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/public/js/ajax_file_upload.js"></script>
<script type="text/javascript" src="/public/js/file_upload.js"></script>
<script type="text/javascript" src="/public/menu/js/jquery.artdialog.js"></script>
<script type="text/javascript" src="/public/menu/js/iframetools.js"></script>
<script type="text/javascript" type="text/javascript">
    $(function () {
        $(".table tr").click(function () {
            var hasSelected = $(this).hasClass("blue");
            $(this)[hasSelected ? "removeClass" : "addClass"]("blue").find(":checkbox").prop("checked", !hasSelected);
        })
        var ue =UM.getEditor('editor',{
            imageUrl:"__CONF_SITE__app/Umupload/uploadFile", //处理图片上传的接口
            imageFieldName:"upfile", //上传图片的表单的name
            imagePath: ""
        });
    });
    /*添加关联商品*/
    function add_goods(title, url, w, h) {
        layer.open({
            type: 2,
            area: [w, h],
            fix: false, //不固定
            maxmin: true,
            shade: 0.4,
            title: title,
            content: url,
            scrollbar: false
        });
    }
    //模块输入信息验证
    function verify(title, short_title, class_id, author, content, article_pic) {
        if (title == '') {
            layer.msg('文章标题不能为空', {icon: 5, time: 1000});
            return false;
        }
        if (short_title == '') {
            layer.msg('文章短标题不能为空', {icon: 5, time: 1000});
            return false;
        }
        if (class_id == '-1') {
            layer.msg('请选择文章类型', {icon: 5, time: 1000});
            return false;
        }
        if (author == '') {
            layer.msg('作者不能为空', {icon: 5, time: 1000});
            return false;
        }
        if (article_pic == '') {
            layer.msg('文章封面不能为空', {icon: 5, time: 1000});
            return false;
        }
//        if (content == '') {
//            layer.msg('内容不能为空', {icon: 5, time: 1000});
//            return false;
//        }
        return true;
    }
    var flag = false;//防止重复提交
    //添加
    function addSuppAjax() {
        var article_id = $("#article_id").val();
        var title = $("#title").val();
        var short_title = $("#short_title").val();
        var class_id = $("#class_id").val();
        var keyword = $("#keyword").val();
        var author = $("#author").val();
        var click = $("#click").val();
        var content = UM.getEditor('editor').getContent();
        var article_pic = $("#article_pic").val();
        var goods_id = $("#goods_id_array").val();
        var link=$("#link").val();
        if ($("#is_recommend").prop("checked")) {
            var is_recommend = 1;
        } else {
            var is_recommend = 0;
        }
        if (verify(title, short_title, class_id, author, content, article_pic) && !flag) {
            flag = true;
            $.ajax({
                type: "post",
                url: "{:url('admin/article/edit_article')}",
                data: {
                    'article_id': article_id,
                    'title': title,
                    'short_title': short_title,
                    'class_id': class_id,
                    'keyword': keyword,
                    'author': author,
                    'click': click,
                    'content': content,
                    'article_pic': article_pic,
                    'is_recommend': is_recommend,
                    'goods_array': goods_id,
                    'link':link
                },
                success: function (data) {
                    if (data['code'] > 0) {
                        layer.msg('修改成功!', {icon: 1, time: 1000}, function () {
                            window.parent.location.href = "__CONF_SITE__admin/article/article_list";
                        });
                    }
                    else {
                        flag = false;
                        layer.msg('修改失败', {icon: 5, time: 1000});
                    }
                }
            });
        }
    }
    function zhu_images(id,path) {
        $("#article_pic").val(path);
        $("#imgarticle_pic").attr('src',path);
    }
    function select_img(number,type) {
        art.dialog.open(('__CONF_SITE__admin/images/dialogalbumlist&number=' + number + '&type=' + type), {
            lock : true,
            title : "我的图片",
            width : 900,
            height : 620,
            drag : false,
            background : "#000000",
            scrollbar:false,
        }, true);
    }
</script>
{/block}